<template>
	<view>
		<view style="margin: 15rpx 20rpx 0 20rpx;">
			<u-search placeholder="输入剧名搜索" v-model="keyword" @search="search" @custom="search"></u-search>
		</view>
		<u-tabs :list="list" :is-scroll="false" v-model="current" @change="change" active-color="#c30f11"
			inactive-color="#f2c351"></u-tabs>

		<!-- 首页导航栏图标自定义组件navbar -->
		<videolist :videoList="videoList"></videolist>
	</view>
</template>

<script>
	import videolist from '@/components/videolist/videolist.vue';
	export default {
		data() {
			return {
				keyword: "",
				list: [],
				current: 0,
				videoList: [],
				page: 1,
				scrollTop: 0,
				fl: [],
				lastscrollTop: 0
			};
		},
		async onReachBottom() {
			var that = this;
			console.log("触底了this.page=", this.page)
			if (this.indexTab == "精选") {
				vk.callFunction({
					url: 'client/pages/pub/index_videolist',
					loading: false, //静默登录，不显示loading
					data: {
						appid: vk.vuex.get('$app.appid'),
						page: that.page
					},
					success: (data) => {
						that.videoList = that.videoList.concat(data.videoList)
						that.page = that.page + 1;
					}
				});
				return;
			}
		},
		onLoad() {

			// vk.callFunction({
			// 	url: 'client/pages/pub/index_appdata',
			// 	data: {
			// 		appid: vk.vuex.get('$app.appid'),
			// 		erindex_cate:'全部'
			// 	},
			// 	success: (res) => {
			// 		vk.hideLoading();
			// 		console.log("vkres:", res);
			// 		this.videoList = res.ervideoList; 

			// 	}
			// });//加载APP数据，用户未登录也可以获取
		},
		onShow() {
			console.log("打印二级分类", vk.vuex.get('$app.index_activity'));
			this.fl = vk.vuex.get('$app.index_activity').fl_tags
			console.log("二级", this.fl);
			const outputArray = this.fl.map(item => ({
				name: item
			}));

			console.log("最终妆化", outputArray);
			this.list = outputArray
			this.change({
				name: "全部"
			})

			// this.list=	vk.vuex.get('$app.index_activity')

		},
		methods: {
			search() {
				if (!this.keyword) {
					vk.toast('搜索词不能为空')
					return;
				}
				uni.navigateTo({
					url: "/pages/index/search?keyword=" + this.keyword
				})
			},

			// async loadAppData() {
			// 	vk.callFunction({
			// 		url: 'client/pages/pub/index_appdata',
			// 		data: {
			// 			appid: vk.vuex.get('$app.appid')
			// 		},
			// 		success: (res) => {
			// 			vk.hideLoading();
			// 			console.log("vkres:", res);
			// 			this.videoList = res.videoList; //首页推荐视频
			// 			// 			this.swiperList = res.swiperList; //首页轮播图
			// 			// 			this.auiPoster.pic = res.indexpic; //首页弹窗图片
			// 			// 			this.index_activity = res.active; //首页弹窗活动(每次进入都弹)
			// 			// 			vk.vuex.set('$app.index_activity', res.active);
			// 			// 			this.xrsc = res.xrsc; //新人首充配置信息

			// 			// uni.setStorageSync("dataList", res.dataList); //推荐视频数据放到缓存
			// 			// vk.vuex.set('$app.ucenter_icons', res.ucenter_icons) //个人中心导航图标
			// 			//当找到对应数据时，替换掉默认数据
			// 			if (res.index_icons.length > 0) {
			// 				this.iconList = []
			// 				this.iconList = res.index_icons
			// 			}
			// 			//active开关值为true，则直接弹窗
			// 			if (res.active.status) {
			// 				this.$refs.poster2.show();
			// 			}
			// 		}
			// 	});
			// },
			async change(res) {
				console.log("类型", res.name);


				if (res.name == '全部') {
					vk.callFunction({
						url: 'client/pages/pub/index_appdata',
						data: {
							appid: vk.vuex.get('$app.appid'),
							erindex_cate: res.name
						},
						success: (res) => {
							vk.hideLoading();
							console.log("vkres:", res);
							this.videoList = res.ervideoList;

						}
					});
				} else {
					console.log("11");
					vk.callFunction({
						url: 'client/pages/pub/index_appdata',
						data: {
							appid: vk.vuex.get('$app.appid'),
							erindex_cate: res.name
						},
						success: (res) => {
							vk.hideLoading();
							console.log("vkres:", res);
							this.videoList = res.flList;

						}
					});
				}


			},
		}
	}
</script>

<style lang="scss">


</style>